<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="订单管理" title-size="36" title-color="#333"></u-navbar>
        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#0F76BC"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging"
            v-model="itemList"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList" :key="index1">
                <view class="order-top">
                  <view class="top-lef">
                    <view
                      v-if="item.status == 2"
                      style="color: #0f76bc; border: solid 2rpx #0f76bc"
                      class="order-top-tip"
                    >
                      展示中
                    </view>
                    <view
                      v-else-if="item.status == 3"
                      style="color: #ffac0e; border: solid 2rpx #ffac0e"
                      class="order-top-tip"
                    >
                      审核中
                    </view>
                    <view
                      v-else-if="item.status == 4"
                      style="color: #999999; border: solid 2rpx #999999"
                      class="order-top-tip"
                    >
                      已下架
                    </view>
                    <text
                      @click="onMore(index1)"
                      style="margin-top: -30rpx; margin-left: 25rpx; font-size: 55rpx"
                      >...</text
                    >
                  </view>
                  <view class="top-rig">
                    <view class="total">
                      已售20件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 收入220
                    </view>
                  </view>

                  <view v-if="moreIndex === index1" class="more">
                    <view v-if="item.status == 4" class="more-item"> 上架视频 </view>
                    <view v-if="item.status == 2" class="more-item"> 下架视频 </view>
                    <view class="more-item"> 删除视频 </view>
                  </view>
                </view>

                <view class="goods-video" @click="onOrderDetail(item)">
                  <view class="orde-lef">
                    <u-icon
                      style="border-radius: 10rpx"
                      name="/static/img/gimg.png"
                      size="200"
                    ></u-icon>
                  </view>
                  <view class="orde-rig">
                    <view class="goods-item">
                      <view class="" style="text-align: end; border-radius: 10rpx">
                        <u-icon
                          style=""
                          class="goods-img"
                          name="/static/img/gimg.png"
                          size="140"
                        ></u-icon>
                      </view>

                      <view class="goods-desc">
                        <view class="goods-title"> 产品名称餐品名称 </view>
                        <view class="goods-price"> ¥88.60 </view>
                      </view>
                    </view>
                    <view class="" style="margin-bottom: 15rpx"> 关联商品 </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging2"
            v-model="itemList2"
            @query="queryList2"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view class="itemView" v-for="(item, index1) in itemList" :key="index1">
                <view class="order-top">
                  <view class="top-lef">
                    <view style="color: #0f76bc; border: solid 2rpx #0f76bc" class="order-top-tip">
                      审核中
                    </view>
                    <text>...</text>
                  </view>
                  <view class="top-rig">
                    <view class="total">
                      已售20件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 收入220
                    </view>
                  </view>
                </view>

                <view class="goods-video" @click="onOrderDetail(item)">
                  <view class="orde-lef">
                    <u-icon
                      style="border-radius: 10rpx"
                      name="/static/img/gimg.png"
                      size="200"
                    ></u-icon>
                  </view>
                  <view class="orde-rig">
                    <view class="goods-item">
                      <view class="" style="text-align: end; border-radius: 10rpx">
                        <u-icon
                          style=""
                          class="goods-img"
                          name="/static/img/gimg.png"
                          size="140"
                        ></u-icon>
                      </view>

                      <view class="goods-desc">
                        <view class="goods-title"> 产品名称餐品名称 </view>
                        <view class="goods-price"> ¥88.60 </view>
                      </view>
                    </view>
                    <view class="" style="margin-bottom: 15rpx"> 关联商品 </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging3"
            v-model="itemList3"
            @query="queryList3"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class="top-lef">
                    <view style="color: #ffac0e; border: solid 2rpx #ffac0e" class="order-top-tip">
                      展示中
                    </view>
                    <text>...</text>
                  </view>
                  <view class="top-rig">
                    <view class="total">
                      已售20件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 收入220
                    </view>
                  </view>
                </view>

                <view class="goods-video">
                  <view class="orde-lef">
                    <u-icon
                      style="border-radius: 10rpx"
                      name="/static/img/gimg.png"
                      size="200"
                    ></u-icon>
                  </view>
                  <view class="orde-rig">
                    <view class="goods-item">
                      <view class="" style="text-align: end; border-radius: 10rpx">
                        <u-icon
                          style=""
                          class="goods-img"
                          name="/static/img/gimg.png"
                          size="140"
                        ></u-icon>
                      </view>

                      <view class="goods-desc">
                        <view class="goods-title"> 产品名称餐品名称 </view>
                        <view class="goods-price"> ¥88.60 </view>
                      </view>
                    </view>
                    <view class="" style="margin-bottom: 15rpx"> 关联商品 </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging4"
            v-model="itemList4"
            @query="queryList4"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class="top-lef">
                    <view style="color: #999999; border: solid 2rpx #999999" class="order-top-tip">
                      已下架
                    </view>
                    <text>...</text>
                  </view>
                  <view class="top-rig">
                    <view class="total">
                      已售20件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 收入220
                    </view>
                  </view>
                </view>

                <view class="goods-video">
                  <view class="orde-lef">
                    <u-icon
                      style="border-radius: 10rpx"
                      name="/static/img/gimg.png"
                      size="200"
                    ></u-icon>
                  </view>
                  <view class="orde-rig">
                    <view class="goods-item">
                      <view class="" style="text-align: end; border-radius: 10rpx">
                        <u-icon
                          style=""
                          class="goods-img"
                          name="/static/img/gimg.png"
                          size="140"
                        ></u-icon>
                      </view>

                      <view class="goods-desc">
                        <view class="goods-title"> 产品名称餐品名称 </view>
                        <view class="goods-price"> ¥88.60 </view>
                      </view>
                    </view>
                    <view class="" style="margin-bottom: 15rpx"> 关联商品 </view>
                  </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>

    <view class="handle-btn-area">
      <view class="handle-btn" @click="routeTo('/other_center/mer-video-push/mer-video-push')">
        <u-icon name="../../static/img/fbxx.png" size="55rpx"></u-icon>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      imgStyle: {
        width: '12rem'
      },
      moreIndex: '',
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部(120)'
        },
        {
          name: '审核中(5)'
        },
        {
          name: '展示中(33)'
        },
        {
          name: '已下架（9）'
        }
      ],
      itemList: [
        {
          status: 2
        },
        {
          status: 3
        },
        {
          status: 4
        }
      ],
      itemList2: [
        {
          status: 2
        }
      ],
      itemList3: [
        {
          status: 3
        }
      ],
      itemList4: [
        {
          status: 4
        }
      ],
      order_id: ''
    }
  },
  onLoad(res) {
    let self = this
    this.$nextTick(function () {
      self.current = Number(res.index) ? Number(res.index) : 0
      self.scurrent = Number(res.index) ? Number(res.index) : 0
      //self.onOrderLoad(self.current, null, true);
    })
  },
  onShow() {
    let self = this
    this.$nextTick(function () {
      //self.onOrderLoad(self.current, null, true);
    })
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      let current = e.detail.current
      this.scurrent = current
      this.current = current
      this.$refs.uTabs.setFinishCurrent(current)
      if (this.current != current) {
        this.onOrderLoad(current, null, true)
      }
    },
    queryList(page, pageSize) {
      this.initData(page, pageSize, '')
    },
    queryList2(page, pageSize) {
      this.initData(page, pageSize, '0')
    },
    queryList3(page, pageSize) {
      this.initData(page, pageSize, '1')
    },
    queryList4(page, pageSize) {
      this.initData(page, pageSize, '2')
    },
    queryList5(page, pageSize) {
      this.initData(page, pageSize, '3')
    },
    queryList6(page, pageSize) {
      this.initData(page, pageSize, '3')
    },
    initData(page, pageSize, status) {
      // let self = this;
      // self.$u.api.getOrderList({
      // 	limit: pageSize,
      // 	page: page,
      // 	status: status
      // }).then(res => {
      // 	self.onOrderLoad(self.current, res.list, false);
      // }).catch(res => {
      // 	self.onOrderLoad(self.current, null, false);
      // });
    },
    onOrderLoad(current, orderList, loading) {
      let self = this
      switch (Number(current)) {
        case 0:
          if (loading) {
            self.$refs.paging.reload()
          } else {
            self.$refs.paging.complete(orderList)
          }
          break
        case 1:
          if (loading) {
            self.$refs.paging2.reload()
          } else {
            self.$refs.paging2.complete(orderList)
          }
          break
        case 2:
          if (loading) {
            self.$refs.paging3.reload()
          } else {
            self.$refs.paging3.complete(orderList)
          }
          break
        case 3:
          if (loading) {
            self.$refs.paging4.reload()
          } else {
            self.$refs.paging4.complete(orderList)
          }
          break
        case 4:
          if (loading) {
            self.$refs.paging5.reload()
          } else {
            self.$refs.paging5.complete(orderList)
          }
          break
      }
    },
    onOrderCancel(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '确定要取消订单吗？', () => {
        self.$u.api.setOrderCancel(item.id).then((res) => {
          self.$u.toast('取消成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onOrderPayment(item) {
      let self = this
      // self.$u.api.setTestPayments({
      // 	order_no: item.order_no,
      // 	openid: uni.getStorageSync('openid')
      // }).then(res => {
      // 	setTimeout(function() {
      // 		self.onOrderLoad(self.current, null, true);
      // 	}, 500);
      // });
      this.$utils.route({
        url: '/goods/payment/payment',
        params: {
          order_id: item.id,
          money: item.pay_price,
          total_weight: item.total_weight,
          delivery_price: item.delivery_price
        }
      })
    },
    onOrderConfrim(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '该订单确认收货吗？', () => {
        self.$u.api.setOrderConfirm(item.id).then((res) => {
          self.$u.toast('收货成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onResellPush(item) {
      this.$utils.route({
        url: '/goods/resell-push/resell-push',
        params: {
          id: item.id
        }
      })
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    },
    onOrderDetail(item) {
      this.$utils.route({
        url: '/other_center/mer-order-details/mer-order-details',
        params: {
          id: item.id
        }
      })
    },
    onMore(e) {
      if (e === this.moreIndex) {
        this.moreIndex = ''
        return
      }
      this.moreIndex = e
    },
    routeTo(url) {
      uni.navigateTo({
        url
      })
    }
  }
}
</script>

<style>
page {
  height: 100%;
  background: #f0f1f2;
}

.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  background-color: #ffffff;
  margin-bottom: 1rem;
  border-radius: 6px;
  padding: 20rpx;
}

.order-lef {
  flex: 3;
}
.order-rig {
  flex: 7;
}
.order-top {
  display: flex;
  padding: 15rpx 0;
  font-size: 30rpx;
  position: relative;
}

.more {
  position: absolute;
  top: 85rpx;
  left: -5rpx;
  width: 160rpx;
  background-color: #fff;
  z-index: 999;
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.12),
    0 0 6px rgba(0, 0, 0, 0.04);
}
.more-item {
  padding: 20rpx;
  height: 80rpx;
  border-bottom: #ededed solid 2rpx;
}

.order-top-tip {
  display: inline-block;
  color: #999999;
  padding: 8rpx 10rpx;
  font-size: 26rpx;
  border-radius: 10rpx;
}
.top-lef {
  flex: 3;
  display: flex;
  align-items: center;
}
.top-rig {
  flex: 7;
  font-size: 30rpx;
  color: #666666;
}

.goods-desc {
  margin-left: 15rpx;
  line-height: 60rpx;
}

.total {
  background-color: #f2f2f2;
  padding: 12rpx 15rpx;
  border-radius: 10rpx;
}

.goods-video {
  display: flex;
}

.orde-lef {
  flex: 3;
}
.orde-rig {
  flex: 7;
  display: flex;
  flex-direction: column-reverse;
}

.goods-item {
  display: flex;
}

.goods-img {
  border-radius: 20rpx;
}

.orde-riget {
  width: 100%;
  margin-left: 10rpx;
  line-height: 55rpx;
  font-size: 26rpx;
}

.goods-speci {
  position: relative;
}

.goods-num {
  position: absolute;
  top: 0;
  right: 0;
  color: #999999;
}

.goods-price {
  font-size: 30rpx;
  color: #f54831;
}

.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 28rpx;
  margin: 15rpx 0;
}

.btn-group {
  display: flex;
  flex-direction: row-reverse;
}

.btn {
  display: inline-block;
  padding: 15rpx 20rpx;
  border-radius: 35rpx;
  font-size: 28rpx;
  margin-left: 15rpx;
}

.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}

.solid-btn {
  background-color: #0f76bc;
  color: #fff;
}

.handle-btn-area {
  position: fixed;
  right: 20rpx;
  bottom: 150rpx;
  z-index: 9999;
  display: flex;
  flex-direction: column;
}

.handle-btn {
  margin-bottom: 20rpx;
  width: 120rpx;
  height: 120rpx;
  background-color: #0f76bc;
  border-radius: 100rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
